package practice_2025_8_4;

class Solution {
    /**
     * 提莫攻击
     * @param timeSeries
     * @param duration
     * @return
     */
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        // 中毒 duration
        // 非递减 timeSeries
        // laststart + dur < time[i] -> + dur
        // laststart + dur >= time[i] -> + time[i] - last
        int count = duration;
        for(int i = 1; i < timeSeries.length; i++) {
            if (timeSeries[i - 1] + duration < timeSeries[i]) {
                count += duration;
            } else {
                count += (timeSeries[i] - timeSeries[i - 1]);
            }
        }
        return count;
    }
}